﻿using System;
using System.Linq;
using System.Linq.Expressions;
using ASPItalia.ModelVirtualCasting.Common;
using ASPItalia.ModelVirtualCasting.ObjectModel;

namespace ASPItalia.ModelVirtualCasting.EntityFramework
{
	public class CountryRepository : BaseRepository<Country>, ICountryRepository
	{
		public CountryRepository(IContextContainer container) : base(container) { }

		public IQueryable<Country> GetAll()
		{
			return CurrentObjectQuery;
		}

		public IQueryable<Country> Where(Expression<Func<Country, bool>> predicate)
		{
			return CurrentObjectQuery.Where(predicate);
		}

		public long Count(System.Linq.Expressions.Expression<Func<Country, bool>> predicate)
		{
			return CurrentObjectQuery.Count(predicate);
		}

        public Country GetByID(int id)
        {
            return this.Where(c => c.CountryID == id).Single();
        }

		public ICountryRepository Include(params string[] paths)
		{
			CurrentObjectQuery = CreateObjectQuery().Include(paths);
			return this;
		}

		#region IReadOnlyRepository<ICountryRepository,Country> Members


		public ICountryRepository EnableLazyLoading()
		{
			SetLazyLoading(true);
			return this;
		}

		public ICountryRepository DisableLazyLoading()
		{
			SetLazyLoading(false);
			return this;
		}

		#endregion
	}
}